<?php
$form = $this->beginWidget('CActiveForm', array(
    'id'    => 'myForm',
    'focus' => array($model, 'full_name'),
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),
    'errorMessageCssClass' => 'txtError'
));
$modelName = get_class($model) . '_';
?>

<?php
if ($model->isEntering) {
    $htmlClass_1 = 'inputNull';
    $htmlClass_2 = '';
} else {
    $htmlClass_1 = 'textMask';
    $htmlClass_2 = 'inputNull';
}
$aField = array(
    'full_name',
    'address',
    'email',
    'phone',
);
foreach ($aField as $attrName) {
    $attrMaskName = 'mask_' . $attrName;

    echo CHtml::openTag('div');

    echo CHtml::textField($attrMaskName, $model->getAttributeLabel($attrName) . ':', array(
        'id'    => $attrMaskName,
        'class' => $htmlClass_1,
        'ref'   => $modelName . $attrName,
    ));
    echo $form->textField($model, $attrName, array(
        'class' => $htmlClass_2,
        'title' => $model->getAttributeLabel($attrName),
    ));

    echo $form->error($model, $attrName);
    echo CHtml::closeTag('div');
}
?>

<div>
    <?php
    $attrName = 'content';
    $attrMaskName = 'mask_' . $attrName;

    echo CHtml::textArea($attrMaskName, $model->getAttributeLabel($attrName) . ':', array(
        'id'    => $attrMaskName,
        'class' => $htmlClass_1,
        'ref'   => $modelName . $attrName,
    ));
    echo $form->textArea($model, $attrName, array(
        'class' => $htmlClass_2,
        'title' => $model->getAttributeLabel($attrName),
    ));
    echo $form->error($model, $attrName);
    ?>
</div>

<div>
    <?php
    $attrName = 'file';
    echo '<label style="float: left; margin:5px 10px 0 0;">Tài liệu đính kèm: </label>';
    echo $form->fileField($model, $attrName, array('class' => 'file'));
    echo $form->error($model, $attrName);
    ?>
</div>
    
<div class="contactCaptcha">
    <?php
    //verify_code
    $attrName = 'verify_code';
    $attrMaskName = 'mask_' . $attrName;

    echo CHtml::textField($attrMaskName, $model->getAttributeLabel($attrName), array(
        'id'    => $attrMaskName,
        'class' => $htmlClass_1,
        'ref'   => $modelName . $attrName,
    ));
    echo $form->textField($model, $attrName, array(
        'style' => 'ime-mode: disabled;', 
        'class' => $htmlClass_2,
        'title' => $model->getAttributeLabel($attrName),
    ));
    //captcha
    $this->widget('ext.mylib.widgets.Captcha.DCaptcha', array(
        'buttonLabel'   => '',
        'buttonType'    => '',
        'buttonOptions' => false,
//        'buttonType'    => 'button',
//        'buttonOptions'    => array(
//            'id' => 'captchaRefresh',
//            'title' => 'Click vào để đổi chữ khác',
//        ),
        'clickableImage' => true,
        'imageOptions'   => array(
            'title' => Yii::t('msg', 'captcha_title'),
            'style' => 'cursor:pointer; margin-left: 10px;',
        ),
    ));
    echo $form->error($model, $attrName);
    ?>
</div>
<div class="blockHeight20"></div>

<div class="control" style="text-align: right;">
    <input class="inputNull" id="btnSubmit" type="submit" value="GỬI" />
    <button class="myBtn myBtnNormal" id="submit" type="button">GỬI</button>
    <button class="myBtn myBtnNormal" id="reset" type="button">XÓA</button>
</div>

<?php $this->endWidget(); ?>
<div id="null" class="null"></div>

<script type="text/javascript">
$('#submit').click(function(){
//    $('#myForm').submit();
    $('#btnSubmit').trigger('click');
});

$('#reset').click(function(){
    window.location = '<?php echo Yii::app()->createUrl('dfront/home/contact') ?>';
    return false;
});

<?php if (Yii::app()->user->hasState('message')) : ?>
    var params = {
        msg: '<?php echo Yii::t('msg', Yii::app()->user->getState('message')); ?>',
        title: '<?php echo Yii::t('label', 'notify') ?>'
    };
    $('#null').showAlert(params, '');
<?php
Yii::app()->user->setState('message', null);
endif;
?>
</script>